﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using yq.CacheHelp;

namespace yq.CacheHelp
{
    /// <summary>
    /// 缓存更新收集器
    /// </summary>
    public class CaCheRefresh
    {
        IList<FullAndId> list = new List<FullAndId>();

        /// <summary>
        /// 获取收卷的列表
        /// </summary>
        /// <returns></returns>
        public IList<FullAndId> Get()
        {
            return list;
        }

        /// <summary>
        /// 添加对象
        /// </summary>
        /// <param name="id"></param>
        public void Add<T>(string id,object obj) where T : new()
        {
            list.Add(new FullAndId() 
            { 
                Fullname = new T().GetType().FullName,
                Id = id, Object = obj, 
                Type= CaCheRefreshType.Add 
            });
        }

        public void Delete<T>(string id) where T : new()
        {
            list.Add(new FullAndId() 
            { 
              Fullname = new T().GetType().FullName,
              Id = id, 
              Type= CaCheRefreshType.Delete 
            });
        }

        public void Update<T>(string id, object obj) where T : new()
        {
            list.Add(new FullAndId() 
            {
                Fullname = new T().GetType().FullName,
                Id = id,
                Object = obj ,
                Type= CaCheRefreshType.Update
            });
        }
    }

    /// <summary>
    /// 修改方式
    /// </summary>
    public enum CaCheRefreshType
    {
        Delete,
        Add,
        Update,
        Clear
    }

    public class FullAndId
    {
        public string Fullname
        {
            get;
            set;
        }

        public string Id
        {
            get;
            set;
        }

        public object Object
        {
            get;
            set;
        }

        public CaCheRefreshType Type
        {
            get;
            set;
        }
        
    }
}
